<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <meta charset="UTF-8" />
    <title>Cases Detail</title>
    <link rel="stylesheet" type="text/css" media="all" href="/layui/css/layui.css"/>
    <script type="text/javascript" src="/layui/layui.all.js"></script>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/myJs.js"></script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>资源修改</legend>
</fieldset>

<div class="layui-container">
    <!--6/12 布局-->
    <div class="layui-row">
        <div class="layui-col-xs8 layui-col-md-offset3">
            <form id="SourceForm" class="layui-form layui-form-pane" >

                <div class="layui-form-item">
                    <label class="layui-form-label">ID</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px ;width: 300px" type="text" name="sourseID" th:value="${t.sourseID}" readonly="readonly" autocomplete="off" class="layui-input layui-badge" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="title" th:value="${t.title}" autocomplete="off" class="layui-input " />
                    </div>
                </div>


                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label">简介</label>-->
                    <!--<div class="layui-input-inline">-->
                        <!--<input style="height: 38px;width: 300px" type="text" name="fileExplain" autocomplete="off" class="layui-input" th:value="${t.fileExplain}" />-->
                    <!--</div>-->
                <!--</div>-->


  <!--              <div class="layui-form-item">
                    <label class="layui-form-label">种类</label>
                    <div class="layui-input-inline">
                        <datalist id="modulelist">
                            <option label="文章" value="Article" />
                            <option label="宣讲视频" value="Video" />
                            <option label="宣传课件" value="CourseWare" />
                            <option label="公司制度" value="System" />
                        </datalist>
                        <input type="text" list="modulelist" th:value="${t.type}" name="type" autocomplete="off" class="layui-input" />
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label ">一级目录:</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <select name="type2"  id="type2" lay-filter="SelOne">
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label ">二级目录:</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <select name="type" id="type" lay-filter="SelTwo">
                            <!--<option th:value="${t.moudle}">default type</option>-->
                        </select>
                    </div>
                </div>
                <!--<div class="layui-form-item">-->
                    <!--<label class="layui-form-label"></label>-->
                    <!--<div class="layui-input-inline">-->
                        <!--<datalist id="modulelist">-->

                        <!--</datalist>-->
                        <!--<input style="height: 38px;width: 300px" type="text" list="modulelist" th:value="${t.type}" name="type" autocomplete="off" class="layui-input"/>-->
                    <!--</div>-->
                <!--</div>-->

                <div class="layui-form-item">
                    <label class="layui-form-label">文章链接</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="link" th:value="${t.link}" autocomplete="off" class="layui-input " />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">上传人</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="leader" th:value="${t.leader}" readonly="readonly" autocomplete="off" class="layui-input " />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">上传时间</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="dtCreateTime" th:value="${t.dtCreateTime}" readonly="readonly" autocomplete="off" class="layui-input " />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">下载次数</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="downCount" th:value="${t.downCount}" readonly="readonly" autocomplete="off" class="layui-input " />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">阅读次数</label>
                    <div class="layui-input-inline">
                        <input style="height: 38px;width: 300px" type="text" name="readCount" th:value="${t.readCount}" readonly="readonly" autocomplete="off" class="layui-input " />
                    </div>
                </div>
                <!--提交按钮-->
                <div class="layui-form-item">
                    <div class="layui-input-block " >
                        <button type="reset" style="width: 190px" class="layui-btn" lay-filter="update" id="update" lay-submit="">立即提交</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>

<script th:inline="javascript" type="text/javascript">
    $(function () {
        var yiji = [[${types}]];
        var result1 ='<option value="' + yiji + '">' + yiji + '</option>';
        var result2=  '<option value="微信文章">微信文章</option>';
        var result3 =  '<option value="宣传视频">宣传视频</option>';
        var result4 =  '<option value="培训课件">培训课件</option>';
        var result5 =  '<option value="公司制度">公司制度</option>';
        $('#type2').append(result1).append(result2).append(result3).append(result4).append(result5);

        var  erji = [[${module}]];
        var result = '<option value="' + erji + '">' + erji + '</option>'
        $('#type').append(result);
        layui.use('form', function(){
            var form = layui.form;
            form.render();
        });
    })
    layui.use('form', function(){
        var form = layui.form;
        form.on('select(SelOne)',function (data) {
            var tt = data.value;
            $.get(
                "/Request/typeSelect", {}, function (data) {
                    var objectD = JSON.parse(data);
                    var Res;
                    $.each(objectD.rows, function (key, value) {
                        if (value.name.indexOf(tt) != -1 ){
                            var result ='<option value="' + value.name + '">' + value.name.substr(5,value.name.length) + '</option>';
                            Res += result;
                        }
                    });
                    $('#type').empty().append(Res);
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }
            )
        })
    });

    function serializeObject(form){
        var o ={};
        $.each(form.serializeArray(),function(index){
            if(o[this['name']]){
                o[this['name']] = o[this['name']] +","+this['value'];

            }else{
                o[this['name']] = this['value'];
            }
        });
        return o;
    }
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(update)', function(data){

            var form= $("#SourceForm");
            var model= serializeObject(form);
            $.ajax({
                type: "post",
                url: "/Request/updateOnefile",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(model),
                dataType: "json",
                success: function(data) {
                    if (data=="true"){
                        layer.confirm('修改成功', function(index){
                            loadPage("/plateForm/Staff_ResourseList");
                        });
                    }else {
                        layer.alert("修改失败");
                        loadPage("#");

                    }

                 }
            });
        });
    });
</script>
</body>
</html>